<template>
	<view class="cg-search">
		<view class="cg-search-btn" v-if="showSearch">

			<cg-image src="icon/sousuo.png" width="81rpx" height="81rpx" @click="openPopup"></cg-image>
			<cg-image src="icon/bg-refresh.png" width="68rpx" height="68rpx" @click="refresh"></cg-image>
		</view>
		<u-popup @close="onClose" :show="popup" v-bind="$attrs" mode="center">
			<view class="cg-popup-content" :style="{width:'90vw'}">
				<view class="">
					输入手机号搜索
				</view>
				<view class="">
					<input type="number" placeholder="输入手机号搜索" v-model="mobile">
				</view>
				<view class="cg-justify-end">
					<view class="btn cg-color666" @click="popup = false">
						取消
					</view>
					<view class="btn cg-main-color" @click="search">
						确定
					</view>
				</view>
			</view>
		</u-popup>
		<view class="bottom-place">

			<view class="bottom">
				<view class="cg-space-around cg-align-center border" v-if="showPage">
					<view class="" @click="prePage">
						<view class="" :class="{'cg-color999':pageInfo.current_page<=1}">
							上一页
						</view>
					</view>
					<view class="">
						{{(pageInfo.current_page )+'/'+(pageInfo.last_page )}}
					</view>
					<view class="" @click="nextPage">
						<view class="" :class="{'cg-color999':pageInfo.current_page>=pageInfo.last_page}">
							下一页
						</view>
					</view>
				</view>
				<view class="cg-align-center cg-justify-center" v-if="showTotal">
					共:{{pageInfo.total}}条
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "cg-search",
		props: {
			showSearch: {
				default: true,
				type: Boolean
			},
			showPage: {
				default: true,
				type: Boolean
			},
			showTotal: {
				default: true,
				type: Boolean
			},
			pageInfo: {
				default: () => {
					return {
						"total": 0,
						"per_page": "15",
						"current_page": 1,
						"last_page": 0,
					}
				},
				type: Object
			}
		},
		data() {
			return {
				popup: false,
				mobile: ''
			};
		},
		methods: {
			prePage() {
				if (this.pageInfo.current_page <= 1) return
				this.$emit('search', {
					page: this.pageInfo.current_page - 1,
					mobile: this.mobile
				})
			},
			nextPage() {
				if (this.pageInfo.current_page >= this.pageInfo.last_page) return
				this.$emit('search', {
					page: this.pageInfo.current_page + 1,
					mobile: this.mobile
				})
			},
			onClose() {
				this.popup = false;
			},
			search() {
				this.popup = false;
				this.$emit('search', {
					page: this.pageInfo.current_page,
					mobile: this.mobile
				})
			},
			refresh() {
				this.popup = false;
				this.$emit('search', {
					page: 1,
					mobile: ''
				})
			},
			openPopup() {
				this.mobile = '';
				this.popup = true;

			}
		}
	}
</script>

<style lang="scss" scoped>
	.cg-search-btn {
		position: fixed;
		top: 20vh;
		right: 0;
	}

	:deep(.u-popup__content) {
		background-color: transparent;
	}

	.cg-popup-content {
		background-color: $bgColor;
		border-radius: 20rpx;
		// height: 200rpx;
		padding: 30rpx;
		box-sizing: border-box;

		input {
			margin: 30rpx 0;
			width: calc(100% - 60rpx);
			background-color: #ffffff;
			border-radius: 10rpx;
			padding: 20rpx;
			font-size: 24rpx;
		}
	}

	.btn {
		margin-left: 40rpx;
	}

	.bottom-place {
		height: 120rpx;

		.bottom {
			height: 120rpx;
			background-color: #e9e9e9;
			position: fixed;
			bottom: 0;
			width: 100%;
			display: flex;
			flex-direction: column;
			justify-content: space-around;

			.border {
				border-bottom: 2rpx solid $borderColor;
				height: 60rpx;
			}
		}
	}
</style>